package com.cn.web.controller.Report;

import com.alibaba.fastjson2.JSONObject;
import com.cn.bean.vo.PartsManagement.ComponentItemClassification;
import com.cn.bean.vo.Report.ItemReport;
import com.cn.mapper.dao.db5.Report.ItemReportDao;
import com.cn.service.server.Report.ItemReportServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/Item")
@Transactional
public class ItemReportController {
    private final ItemReportServer itemReportServer;

    @Autowired(required = false)
    public ItemReportController(ItemReportServer itemReportServer) {
        this.itemReportServer = itemReportServer;
    }

    @RequestMapping("/select/ItemReport")
    @ResponseBody
    public List<ItemReport> selectItemReport(@RequestBody JSONObject jsonObject) {
        Integer page = jsonObject.getInteger("page");
        Integer limit = jsonObject.getInteger("limit");
//        List<ItemReport> selectItemReport(int limit,  int page,  String name, String materialCode, String supplierUniqueCode,
//                String structureName, String partSingleID,
//                String consumableCategoryName, String material, String specification, String model, String materialStatus, String circulationState);
        String name = jsonObject.getString("name");
        String materialCode = jsonObject.getString("materialCode");
        String supplierUniqueCode = jsonObject.getString("supplierUniqueCode");
        String structureName = jsonObject.getString("structureName");
        String partSingleID = jsonObject.getString("partSingleID");
        String consumableCategoryName = jsonObject.getString("consumableCategoryName");
        String material = jsonObject.getString("material");
        String specification = jsonObject.getString("specification");
        String model = jsonObject.getString("model");
        String materialStatus = jsonObject.getString("materialStatus");
        String circulationState = jsonObject.getString("circulationState");
        name = (name != null) ? name : "";
        materialCode = (materialCode != null) ? materialCode : "";
        supplierUniqueCode = (supplierUniqueCode != null) ? supplierUniqueCode : "";
        structureName = (structureName != null) ? structureName : "";
        partSingleID = (partSingleID != null) ? partSingleID : "";
        consumableCategoryName = (consumableCategoryName != null) ? consumableCategoryName : "";
        material = (material != null) ? material : "";
        specification = (specification != null) ? specification : "";
        model = (model != null) ? model : "";
        materialStatus = (materialStatus != null) ? materialStatus : "";
        circulationState = (circulationState != null) ? circulationState : "";
        return itemReportServer.selectItemReport(limit, page,name,materialCode,supplierUniqueCode,structureName,partSingleID,consumableCategoryName,material,specification,model,materialStatus,circulationState);
    }
}
